package com.zretc.minio.config;

import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;

import java.io.File;

@Configuration
public class MultipartConfig {

    @Bean
    public CommonsMultipartResolver multipartResolver() {
        CommonsMultipartResolver resolver = new CommonsMultipartResolver();

        // 创建一个 DiskFileItemFactory 对象
        DiskFileItemFactory factory = new DiskFileItemFactory();

        // 设置临时文件存储目录
        File repository = new File("e:/temp");
        if (!repository.exists()) {
            repository.mkdirs();
        }
        factory.setRepository(repository);

        // 配置 resolver
        resolver.setMaxUploadSize(10 * 1024 * 1024); // 设置最大上传文件大小
        resolver.setDefaultEncoding("utf-8");

        return resolver;
    }
}
